import React from 'react'

export default function List(props) {
  function handle(e) {
    const value = e.target.value.trim()
    if (e.keyCode !== 13 || !value) return
    props.push(value)
  }
  return (
    <>
      <input type="text" onKeyDown={handle} />
      <ul>
        {props.list.map((item, index) => {
          return <li key={index}>{item}</li>
        })}
      </ul>
    </>
  )
}
